package com.yly.doctorapp.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yly.doctorapp.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderXialaAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> mList;
    private int selectPosition = 0;

    public int getSelectPosition() {
        return selectPosition;
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
    }

    public OrderXialaAdapter(Context mContext, List<String> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            view = View.inflate(mContext, R.layout.layout_orderxialaitem, null);
        } else {
            view = convertView;
        }
        if (null != mList && mList.size() > 0){
            ViewHolder holder = new ViewHolder(view);
            setOrderType(Integer.parseInt(mList.get(position)), holder);
            if (position == getSelectPosition()){
                holder.tvType.setTextColor(0xffa0524b);
                holder.ivSelected.setVisibility(View.VISIBLE);
            }else {
                holder.tvType.setTextColor(0xff666666);
                holder.ivSelected.setVisibility(View.GONE);
            }
        }
        return view;
    }

    private void setOrderType(int type, ViewHolder holder){
        switch (type){
            case -1:
                holder.tvType.setText("全部");
                break;
            case 0:
                holder.tvType.setText("普通产品订单");
                break;
            case 1:
                holder.tvType.setText("中医知识产品订单");
                break;
            case 2:
                holder.tvType.setText("医生推荐产品订单");
                break;
            case 3:
                holder.tvType.setText("咨询费订单");
                break;
            case 4:
                holder.tvType.setText("处方订单");
                break;
        }
    }

    static class ViewHolder {
        @BindView(R.id.tv_type)
        TextView tvType;
        @BindView(R.id.iv_selected)
        ImageView ivSelected;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
